home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / docs.lha / cmu-user / cmu-user.info-3 < prev    next >
Text File  |  1992-08-05  |  52KB  |  1,454 lines

  1. Info file: cmu-user.info,    -*-Text-*-
  2. produced by latexinfo-format-buffer
  3. from file: cmu-user.tex
  4.  
  5.  
  6. 
  7. File: cmu-user.info  Node: Exiting Commands, Prev: Compiler Policy Control, Up: The Debugger, Next: Information Commands
  8.  
  9. Exiting Commands
  10. ================
  11.  
  12.  
  13. These commands get you out of the debugger.
  14.  
  15.      
  16. `quit'     
  17.      
  18.      Throw to top level.
  19.      
  20. `restart' [N]     
  21.      Invokes the Nth restart case as displayed by the `error' command.
  22.      If N is not specified, the available restart cases are reported.
  23.      
  24. `go'     
  25.      
  26.      Calls `continue' on the condition given to `debug'.  If there is no
  27.      restart case named CONTINUE, then an error is signaled.
  28.      
  29. `abort'     
  30.      
  31.      Calls `abort' on the condition given to `debug'.  This is useful
  32.      for popping debug command loop levels or aborting to top level, as
  33.      the case may be.
  34.      
  35.  
  36.  
  37.  
  38. 
  39. File: cmu-user.info  Node: Information Commands, Prev: Exiting Commands, Up: The Debugger, Next: Breakpoint Commands
  40.  
  41. Information Commands
  42. ====================
  43.  
  44.  
  45. Most of these commands print information about the current frame or
  46. function, but a few show general information.
  47.  
  48.      
  49. `help', `?'     
  50.      
  51.      Displays a synopsis of debugger commands.
  52.      
  53. `describe'     
  54.      
  55.      Calls `describe' on the current function, displays number of local
  56.      variables, and indicates whether the function is compiled or
  57.      interpreted.
  58.      
  59. `print'     
  60.      
  61.      Displays the current function call as it would be displayed by
  62.      moving to this frame.
  63.      
  64. `vprint' (or `pp') [VERBOSITY]     
  65.      Displays the current function call using `*print-level*' and
  66.      `*print-length*' instead of `*debug-print-level*' and
  67.      `*debug-print-length*'.  VERBOSITY is a small integer (default 2)
  68.      that controls other dimensions of verbosity.
  69.      
  70. `error'     
  71.      
  72.      Prints the condition given to `invoke-debugger' and the active
  73.      proceed cases.
  74.      
  75. `backtrace' [N]     
  76.      Displays all the frames from the current to the bottom.  Only shows
  77.      N frames if specified.  The printing is controlled by
  78.      `*debug-print-level*' and `*debug-print-length*'.
  79.      
  80.  
  81.  
  82.  
  83. 
  84. File: cmu-user.info  Node: Breakpoint Commands, Prev: Information Commands, Up: The Debugger, Next: Function Tracing
  85.  
  86. Breakpoint Commands
  87. ===================
  88.  
  89.  
  90. CMU Common Lisp supports setting of breakpoints inside compiled functions and
  91. stepping of compiled code.  Breakpoints can only be set at at known
  92. locations (*Note Unknown Locations and Interrupts::), so these commands are largely
  93. useless unless the `debug' optimize quality is at least `2'
  94. (*Note Compiler Policy Control::).  These commands manipulate breakpoints:
  95. `breakpoint' LOCATION {OPTION VALUE}*     
  96.      
  97.      Set a breakpoint in some function.  LOCATION may be an integer code
  98.      location number (as displayed by `list-locations') or a keyword.
  99.      The keyword can be used to indicate setting a breakpoint at the
  100.      function start (`:start', `:s') or function end (`:end', `:e').
  101.      The `breakpoint' command has `:condition', `:break', `:print' and
  102.      `:function' options which work similarly to the `trace' options.
  103.      
  104. `list-locations' (or `ll') [FUNCTION]     
  105.      List all the code locations in the current frame's function, or in
  106.      FUNCTION if it is supplied.  The display format is the code
  107.      location number, a colon and then the source form for that location:
  108.           
  109.           3: (1- N)
  110.      
  111.      If consecutive locations have the same source, then a numeric range
  112.      like `3-5:' will be printed.  For example, a default function call
  113.      has a known location both immediately before and after the call,
  114.      which would result in two code locations with the same source.  The
  115.      listed function becomes the new default function for breakpoint
  116.      setting (via the `breakpoint') command.
  117.      
  118. `list-breakpoints' (or `lb')     
  119.      List all currently active breakpoints with their breakpoint number.
  120.      
  121. `delete-breakpoint' (or `db') [NUMBER]     
  122.      Delete a breakpoint specified by its breakpoint number.  If no
  123.      number is specified, delete all breakpoints.
  124.      
  125. `step'     
  126.      Step to the next possible breakpoint location in the current function.
  127.      This always steps over function calls, instead of stepping into them
  128.  
  129.  
  130. * Menu:
  131.  
  132. * Breakpoint Example::
  133.  
  134.  
  135. 
  136. File: cmu-user.info  Node: Breakpoint Example, Prev: Breakpoint Commands, Up: Breakpoint Commands
  137.  
  138. Breakpoint Example
  139. ------------------
  140.  
  141.  
  142. Consider this definition of the factorial function:
  143.      
  144.      (defun ! (n)
  145.        (if (zerop n)
  146.            1
  147.            (* n (! (1- n)))))
  148.  
  149. This debugger session demonstrates the use of breakpoints:
  150.      
  151.      common-lisp-user> (break) ; Invoke debugger
  152.      
  153.      Break
  154.      
  155.      Restarts:
  156.        0: [CONTINUE] Return from BREAK.
  157.        1: [ABORT ] Return to Top-Level.
  158.      
  159.      Debug  (type H for help)
  160.      
  161.      (INTERACTIVE-EVAL (BREAK))
  162.      0] ll #'!
  163.      0: #'(LAMBDA (N) (BLOCK ! (IF # 1 #)))
  164.      1: (ZEROP N)
  165.      2: (* N (! (1- N)))
  166.      3: (1- N)
  167.      4: (! (1- N))
  168.      5: (* N (! (1- N)))
  169.      6: #'(LAMBDA (N) (BLOCK ! (IF # 1 #)))
  170.      0] br 2
  171.      (* N (! (1- N)))
  172.      1: 2 in !
  173.      Added.
  174.      0] q
  175.      
  176.      common-lisp-user> (! 10) ; Call the function
  177.      
  178.      *Breakpoint hit*
  179.      
  180.      Restarts:
  181.        0: [CONTINUE] Return from BREAK.
  182.        1: [ABORT ] Return to Top-Level.
  183.      
  184.      Debug  (type H for help)
  185.      
  186.      (! 10) ; We are now in first call (arg 10) before the multiply
  187.      Source: (* N (! (1- N)))
  188.      3] st
  189.      
  190.      *Step*
  191.      
  192.      (! 10) ; We have finished evaluation of (1- n)
  193.      Source: (1- N)
  194.      3] st
  195.      
  196.      *Breakpoint hit*
  197.      
  198.      Restarts:
  199.        0: [CONTINUE] Return from BREAK.
  200.        1: [ABORT ] Return to Top-Level.
  201.      
  202.      Debug  (type H for help)
  203.      
  204.      (! 9) ; We hit the breakpoint in the recursive call
  205.      Source: (* N (! (1- N)))
  206.      3] 
  207.  
  208.  
  209.  
  210.  
  211.  
  212. 
  213. File: cmu-user.info  Node: Function Tracing, Prev: Breakpoint Commands, Up: The Debugger, Next: Specials
  214.  
  215. Function Tracing
  216. ================
  217.  
  218.  
  219. The tracer causes selected functions to print their arguments and their
  220. results whenever they are called.  Options allow conditional printing of
  221. the trace information and conditional breakpoints on function entry or
  222. exit.
  223.  
  224.  
  225.  -- Macro: trace {option global-value}* {name {option value}*}*
  226.  
  227.      `trace' is a debugging tool that prints information when specified
  228.      functions are called.  In its simplest form:
  229.           
  230.           (trace NAME-1 NAME-2 ...)
  231.      
  232.      `trace' causes a printout on trace-output each time that one of the
  233.      named functions is entered or returns (the NAMES are not
  234.      evaluated.)  Trace output is indented according to the number of
  235.      pending traced calls, and this trace depth is printed at the
  236.      beginning of each line of output.  Printing verbosity of arguments
  237.      and return values is controlled by debug-print-level and
  238.      debug-print-length.
  239.      
  240.      If no NAMES or OPTIONS are are given, `trace' returns the list of
  241.      all currently traced functions, `*traced-function-list*'.
  242.      
  243.      Trace options can cause the normal printout to be suppressed, or cause
  244.      extra information to be printed.  Each option is a pair of an option
  245.      keyword and a value form.  Options may be interspersed with function
  246.      names.  Options only affect tracing of the function whose name they
  247.      appear immediately after.  Global options are specified before the first
  248.      name, and affect all functions traced by a given use of `trace'.
  249.      If an already traced function is traced again, any new options replace the
  250.      old options.  The following options are defined:
  251.      \code{:condition} \var{form}, \code{:condition-after} \var{form}, 
  252.           `:condition-all' FORM
  253.                
  254.           If `:condition' is specified, then `trace' does nothing unless
  255.           FORM evaluates to true at the time of the call.
  256.           `:condition-after' is similar, but suppresses the initial
  257.           printout, and is tested when the function returns.
  258.           `:condition-all' tries both before and after.
  259.           
  260.      `:wherein' NAMES     
  261.           If specified, NAMES is a function name or list of names.
  262.           `trace' does nothing unless a call to one of those functions
  263.           encloses the call to this function (i.e. it would appear in a
  264.           backtrace.)  Anonymous functions have string names like
  265.           `"DEFUN FOO"'.
  266.           
  267.      \code{:break} \var{form}, \code{:break-after} \var{form}, 
  268.           `:break-all' FORM
  269.                
  270.           If specified, and FORM evaluates to true, then the debugger is
  271.           invoked at the start of the function, at the end of the
  272.           function, or both, according to the respective option.
  273.           
  274.      \code{:print} \var{form}, \code{:print-after} \var{form},
  275.           `:print-all' FORM
  276.                
  277.           In addition to the usual printout, the result of evaluating
  278.           FORM is printed at the start of the function, at the end of
  279.           the function, or both, according to the respective option.
  280.           Multiple print options cause multiple values to be printed.
  281.           
  282.      `:function' FUNCTION-FORM     
  283.           This is a not really an option, but rather another way of
  284.           specifying what function to trace.  The FUNCTION-FORM is
  285.           evaluated immediately, and the resulting function is traced.
  286.           
  287.      `:encapsulate {:default | t | nil}'     
  288.            
  289.           In CMU Common Lisp, tracing can be done either by temporarily
  290.           redefining the function name (encapsulation), or using
  291.           breakpoints.  When breakpoints are used, the function object
  292.           itself is destructively modified to cause the tracing action.
  293.           The advantage of using breakpoints is that tracing works even
  294.           when the function is anonymously called via `funcall'.
  295.           
  296.           When `:encapsulate' is true, tracing is done via
  297.           encapsulation.  `:default' is the default, and means to use
  298.           encapsulation for interpreted functions and funcallable
  299.           instances, breakpoints otherwise.  When encapsulation is used,
  300.           forms are {not} evaluated in the function's lexical
  301.           environment, but `debug:arg' can still be used.
  302.      
  303.      
  304.      `:condition', `:break' and `:print' forms are evaluated in the
  305.      lexical environment of the called function; `debug:var' and
  306.      `debug:arg' can be used.  The `-after' and `-all' forms are
  307.      evaluated in the null environment.
  308.  
  309.  
  310.  
  311.  -- Macro: untrace  &rest FUNCTION-NAMES
  312.  
  313.      This macro turns off tracing for the specified functions, and
  314.      removes their names from `*traced-function-list*'.  If no
  315.      FUNCTION-NAMES are given, then all currently traced functions are
  316.      untraced.
  317.  
  318.  
  319.  
  320.  
  321.  -- Variable: *traced-function-list*
  322.      A list of function names maintained and used by `trace', `untrace',
  323.      and `untrace-all'.  This list should contain the names of all
  324.      functions currently being traced.
  325.  
  326.  
  327.  
  328.  
  329.  -- Variable: *max-trace-indentation*
  330.      The maximum number of spaces which should be used to indent trace
  331.      printout.  This variable is initially set to 40.
  332.  
  333.  
  334. * Menu:
  335.  
  336. * Encapsulation Functions::     
  337.  
  338.  
  339. 
  340. File: cmu-user.info  Node: Encapsulation Functions, Prev: Function Tracing, Up: Function Tracing
  341.  
  342. Encapsulation Functions
  343. -----------------------
  344.  
  345.  
  346. The encapsulation functions provide a mechanism for intercepting the
  347. arguments and results of a function.  `encapsulate' changes the function
  348. definition of a symbol, and saves it so that it can be restored later.
  349. The new definition normally calls the original definition.  The CMU
  350. Common Lisp fdefinition function always returns the original definition,
  351. stripping off any encapsulation.
  352.  
  353. The original definition of the symbol can be restored at any time by the
  354. `unencapsulate' function.  `encapsulate' and `unencapsulate' allow a
  355. symbol to be multiply encapsulated in such a way that different
  356. encapsulations can be completely transparent to each other.
  357.  
  358. Each encapsulation has a type which may be an arbitrary lisp object.  If
  359. a symbol has several encapsulations of different types, then any one of
  360. them can be removed without affecting more recent ones.  A symbol may
  361. have more than one encapsulation of the same type, but only the most
  362. recent one can be undone.
  363.  
  364.  
  365.  -- Function: encapsulate symbol type body
  366.  
  367.      Saves the current definition of SYMBOL, and replaces it with a
  368.      function which returns the result of evaluating the form, BODY.
  369.      TYPE is an arbitrary lisp object which is the type of
  370.      encapsulation.
  371.      
  372.      When the new function is called, the following variables are bound for the
  373.      evaluation of BODY:
  374.           
  375.      `extensions:argument-list'     
  376.           
  377.           A list of the arguments to the function.
  378.           
  379.      `extensions:basic-definition'     
  380.           
  381.           The unencapsulated definition of the function.
  382.      
  383.      The unencapsulated definition may be called with the original
  384.      arguments by including the form
  385.           
  386.           (apply extensions:basic-definition extensions:argument-list)
  387.      
  388.      
  389.      `encapsulate' always returns SYMBOL.
  390.  
  391.  
  392.   -- Function: unencapsulate symbol type
  393.  
  394.      Undoes SYMBOL's most recent encapsulation of type TYPE.  TYPE is
  395.      compared with `eq'.  Encapsulations of other types are left in
  396.      place.
  397.  
  398.  
  399.  
  400.  -- Function: encapsulated-p symbol type
  401.  
  402.      Returns `t' if SYMBOL has an encapsulation of type TYPE.  Returns
  403.      nil otherwise.  TYPE is compared with `eq'.
  404.  
  405.  
  406.  
  407.  
  408.  
  409. 
  410. File: cmu-user.info  Node: Specials, Prev: Function Tracing, Up: The Debugger
  411.  
  412. Specials
  413. ========
  414.  
  415. These are the special variables that control the debugger action.
  416.  
  417.  
  418.  
  419.  -- Variable: *debug-print-level*
  420.  
  421.  
  422.  -- Variable: *debug-print-length*
  423.      `*print-level*' and `*print-length*' are bound to these values
  424.      during the execution of some debug commands.  When evaluating
  425.      arbitrary expressions in the debugger, the normal values of
  426.      `*print-level*' and `*print-length*' are in effect.  These
  427.      variables are initially set to 3 and 5, respectively.
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434. 
  435. File: cmu-user.info  Node: The Compiler, Prev: The Debugger, Up: Top, Next: Advanced Compiler Use and Efficiency Hints
  436.  
  437. The Compiler
  438. ************
  439.  
  440.  
  441.  
  442. * Menu:
  443.  
  444. * Compiler Introduction::       
  445. * Calling the Compiler::        
  446. * Compilation Units::           
  447. * Interpreting Error Messages::  
  448. * Types in Python::             
  449. * Getting Existing Programs to Run::  
  450. * Compiler Policy::             
  451. * Open Coding and Inline Expansion::  
  452.  
  453.  
  454. 
  455. File: cmu-user.info  Node: Compiler Introduction, Prev: The Compiler, Up: The Compiler, Next: Calling the Compiler
  456.  
  457. Compiler Introduction
  458. =====================
  459.  
  460.  
  461. This chapter contains information about the compiler that every CMU
  462. Common Lisp user should be familiar with.  Chapter ? goes into greater
  463. depth, describing ways to use more advanced features.
  464.  
  465. The CMU Common Lisp compiler (also known as Python) has many features
  466. that are seldom or never supported by conventional Common Lisp
  467. compilers:
  468.      
  469.    * Source level debugging of compiled code (see chapter *Note The Debugger::.)
  470.      
  471.    * Type error compiler warnings for type errors detectable at compile
  472.      time.
  473.      
  474.    * Compiler error messages that provide a good indication of where the
  475.      error appeared in the source.
  476.      
  477.    * Full run-time checking of all potential type errors, with
  478.      optimization of type checks to minimize the cost.
  479.      
  480.    * Scheme-like features such as proper tail recursion and extensive
  481.      source-level optimization.
  482.      
  483.    * Advanced tuning and optimization features such as comprehensive efficiency
  484.      notes, flow analysis, and untagged number representations (see chapter
  485.      ?.)
  486.  
  487.  
  488.  
  489.  
  490. 
  491. File: cmu-user.info  Node: Calling the Compiler, Prev: Compiler Introduction, Up: The Compiler, Next: Compilation Units
  492.  
  493. Calling the Compiler
  494. ====================
  495.  
  496. Functions may be compiled using `compile', `compile-file', or 
  497. `compile-from-stream'.  
  498.  
  499.  
  500.  -- Function: compile  NAME &optional DEFINITION
  501.  
  502.      This function compiles the function whose name is NAME.  If NAME is
  503.      false, the compiled function object is returned.  If DEFINITION is
  504.      supplied, it should be a lambda expression that is to be compiled
  505.      and then placed in the function cell of NAME.  As per the proposed
  506.      X3J13 cleanup "compile-argument-problems", DEFINITION may also be
  507.      an interpreted function.
  508.      
  509.      The return values are as per the proposed X3J13 cleanup
  510.      "compiler-diagnostics".  The first value is the function name or
  511.      function object.  The second value is false if no compiler
  512.      diagnostics were issued, and true otherwise.  The third value is
  513.      false if no compiler diagnostics other than style warnings were
  514.      issued.  A non-false value indicates that there were "serious"
  515.      compiler diagnostics issued, or that other conditions of type error
  516.      or warning (but not style-warning) were signalled during
  517.      compilation.
  518.  
  519.  
  520.  
  521.  
  522.  -- Function: compile-file 
  523.         INPUT-PATHNAME
  524.         &keys :output-file :error-file :trace-file
  525.               :error-output :verbose :print :progress
  526.               :load :block-compile :entry-points
  527.  
  528.      The CMU Common Lisp `compile-file' is extended through the addition of several new
  529.      keywords and an additional interpretation of INPUT-PATHNAME:
  530.           
  531.      INPUT-PATHNAME     
  532.            If this argument is a list of input files, rather than a
  533.           single input pathname, then all the source files are compiled
  534.           into a single object file.  In this case, the name of the
  535.           first file is used to determine the default output file names.
  536.           This is especially useful in combination with BLOCK-COMPILE.
  537.           
  538.      OUTPUT-FILE     
  539.            This argument specifies the name of the output file.  true
  540.           gives the default name, false suppresses the output file.
  541.           
  542.      ERROR-FILE     
  543.            A listing of all the error output is directed to this file.
  544.           If there are no errors, then no error file is produced (and
  545.           any existing error file is deleted.)  true gives "NAME`.err'"
  546.           (the default), and false suppresses the output file.
  547.           
  548.      ERROR-OUTPUT     
  549.           
  550.           If true (the default), then error output is sent to
  551.           `*error-output*'.  If a stream, then output is sent to that
  552.           stream instead.  If false, then error output is suppressed.
  553.           Note that this error output is in addition to (but the same
  554.           as) the output placed in the ERROR-FILE.
  555.           
  556.      VERBOSE     
  557.            If true (the default), then the compiler prints to error
  558.           output at the start and end of compilation of each file.  See
  559.           compile-verbose ?.
  560.           
  561.      PRINT     
  562.           
  563.           If true (the default), then the compiler prints to error
  564.           output when each function is compiled.  See compile-print ?.
  565.           
  566.      PROGRESS     
  567.            If true (default false), then the compiler prints to error
  568.           output progress information about the phases of compilation of
  569.           each function.  This is a CMU extension that is useful mainly
  570.           in large block compilations.  See compile-progress ?.
  571.           
  572.      TRACE-FILE     
  573.            If true, several of the intermediate representations
  574.           (including annotated assembly code) are dumped out to this
  575.           file.  true gives "NAME`.trace'".  Trace output is off by
  576.           default.  ?.
  577.           
  578.      LOAD     
  579.            If true, load the resulting output file.
  580.           
  581.      BLOCK-COMPILE     
  582.            Controls the compile-time resolution of function calls.  By
  583.           default, only self-recursive calls are resolved, unless an
  584.           `ext:block-start' declaration appears in the source file.  ?.
  585.           
  586.      ENTRY-POINTS     
  587.            If non-null, then this is a list of the names of all
  588.           functions in the file that should have global definitions
  589.           installed (because they are referenced in other files.)  ?.
  590.      
  591.      
  592.      The return values are as per the proposed X3J13 cleanup
  593.      "compiler-diagnostics".  The first value from `compile-file' is the
  594.      truename of the output file, or false if the file could not be
  595.      created.  The interpretation of the second and third values is
  596.      described above for `compile'.
  597.  
  598.  
  599.  
  600.  
  601.  -- Variable: *compile-verbose*
  602.  
  603.  -- Variable: *compile-print*
  604.  
  605.  -- Variable: *compile-progress*
  606.      These variables determine the default values for the :verbose,
  607.      :print and :progress arguments to `compile-file'.
  608.  
  609.  
  610.  
  611.  -- Function: compile-from-stream input-stream
  612.         &keys :error-stream
  613.               :trace-stream
  614.               :block-compile :entry-points
  615.  
  616.      This function is similar to `compile-file', but it takes all its
  617.      arguments as streams.  It reads Common Lisp code from INPUT-STREAM
  618.      until end of file is reached, compiling into the current
  619.      environment.  This function returns the same two values as the last
  620.      two values of `compile'.  No output files are produced.
  621.  
  622.  
  623.  
  624.  
  625. 
  626. File: cmu-user.info  Node: Compilation Units, Prev: Calling the Compiler, Up: The Compiler, Next: Interpreting Error Messages
  627.  
  628. Compilation Units
  629. =================
  630.  
  631.  
  632. CMU Common Lisp supports the `with-compilation-unit' macro added to the
  633. language by the proposed X3J13 "with-compilation-unit" compiler cleanup.
  634. This provides a mechanism for eliminating spurious undefined warnings
  635. when there are forward references across files, and also provides a
  636. standard way to access compiler extensions.
  637.  
  638.  
  639.  
  640.  -- Macro: with-compilation-unit 
  641.         ({KEY VALUE}*) {FORM}*
  642.  
  643.      This macro evaluates the FORMS in an environment that causes warnings for
  644.      undefined variables, functions and types to be delayed until all the forms have
  645.      been evaluated.  Each keyword VALUE is an evaluated form.  These keyword
  646.      options are recognized:
  647.           
  648.      :override     
  649.           
  650.           If uses of `with-compilation-unit' are dynamically nested, the
  651.           outermost use will take precedence, suppressing printing of
  652.           undefined warnings by inner uses.  However, when the
  653.           `override' option is true this shadowing is inhibited; an
  654.           inner use will print summary warnings for the compilations
  655.           within the inner scope.
  656.           
  657.      :optimize     
  658.           
  659.           This is a CMU extension that specifies of the "global" compilation policy for
  660.           the dynamic extent of the body.  The argument should evaluate to an
  661.           `optimize' declare form, like:
  662.                
  663.                (optimize (speed 3) (safety 0))
  664.           
  665.           ?
  666.           
  667.      :optimize-interface     
  668.           
  669.           Similar to :optimize, but specifies the compilation policy for
  670.           function interfaces (argument count and type checking) for the
  671.           dynamic extent of the body.  ?.
  672.           
  673.      :context-declarations     
  674.           
  675.           This is a CMU extension that pattern-matches on function
  676.           names, automatically splicing in any appropriate declarations
  677.           at the head of the function definition.  ?.
  678.      
  679.  
  680.  
  681. * Menu:
  682.  
  683. * Undefined Warnings::          
  684. * Context Declarations::        
  685. * Context Declaration Example::  
  686.  
  687.  
  688. 
  689. File: cmu-user.info  Node: Undefined Warnings, Prev: Compilation Units, Up: Compilation Units, Next: Context Declarations
  690.  
  691. Undefined Warnings
  692. ------------------
  693.  
  694.  
  695. Warnings about undefined variables, functions and types are delayed until the
  696. end of the current compilation unit.  The compiler entry functions
  697. (`compile', etc.) implicitly use `with-compilation-unit', so undefined
  698. warnings will be printed at the end of the compilation unless there is an
  699. enclosing `with-compilation-unit'.  In order the gain the benefit of this
  700. mechanism, you should wrap a single `with-compilation-unit' around the calls
  701. to `compile-file', i.e.:
  702.      
  703.      (with-compilation-unit ()
  704.        (compile-file "file1")
  705.        (compile-file "file2")
  706.        ...)
  707.  
  708.  
  709. Unlike for functions and types, undefined warnings for variables are not
  710. suppressed when a definition (e.g. `defvar') appears after the reference
  711. (but in the same compilation unit.)  This is because doing special
  712. declarations out of order just doesn't work -- although early references
  713. will be compiled as special, bindings will be done lexically.
  714.  
  715. Undefined warnings are printed with full source context (?), which
  716. tremendously simplifies the problem of finding undefined references that
  717. resulted from macroexpansion.  After printing detailed information about
  718. the undefined uses of each name, `with-compilation-unit' also prints
  719. summary listings of the names of all the undefined functions, types and
  720. variables.
  721.  
  722.  
  723.  
  724.  -- Variable: *undefined-warning-limit*
  725.      This variable controls the number of undefined warnings for each distinct name
  726.      that are printed with full source context when the compilation unit ends.  If
  727.      there are more undefined references than this, then they are condensed into a
  728.      single warning:
  729.           
  730.           Warning: COUNT more uses of undefined function NAME.
  731.      
  732.      When the value is `0', then the undefined warnings are not broken
  733.      down by name at all: only the summary listing of undefined names is
  734.      printed.
  735.  
  736.  
  737. 
  738. File: cmu-user.info  Node: Context Declarations, Prev: Undefined Warnings, Up: Compilation Units, Next: Context Declaration Example
  739.  
  740. Context Declarations
  741. --------------------
  742.  
  743.  
  744. CMU Common Lisp has a context-sensitive declaration mechanism which is useful because it
  745. allows flexible control of the compilation policy in large systems without
  746. requiring changes to the source files.  The primary use of this feature is to
  747. allow the exported interfaces of a system to be compiled more safely than the
  748. system internals.  The context used is the name being defined and the kind of
  749. definition (function, macro, etc.) 
  750.  
  751. The :context-declarations option to with-compilation-unit *Note Compilation Units:: has
  752. dynamic scope, affecting all compilation done during the evaluation of the
  753. body.  The argument to this option should evaluate to a list of lists of the
  754. form:
  755.      
  756.      (CONTEXT-SPEC {DECLARE-FORM}+)
  757.  
  758. In the indicated context, the specified declare forms are inserted at
  759. the head of each definition.  The declare forms for all contexts that
  760. match are appended together, with earlier declarations getting
  761. precedence over later ones.  A simple example:
  762.      
  763.          :context-declarations
  764.          '((:external (declare (optimize (safety 2)))))
  765.  
  766. This will cause all functions that are named by external symbols to be
  767. compiled with `safety 2'.
  768.  
  769. The full syntax of context specs is:
  770.      
  771. :internal, :external     
  772.      
  773.      True if the symbol is internal (external) in its home package.
  774.      
  775. :uninterned     
  776.      
  777.      True if the symbol has no home package.
  778.      
  779. `(:package {PACKAGE-NAME}*)'     
  780.      
  781.      True if the symbol's home package is in any of the named packages (false if
  782.      uninterned.)
  783.      
  784. :anonymous     
  785.      
  786.      True if the function doesn't have any interesting name (not
  787.      `defmacro', `defun', `labels' or `flet').
  788.      
  789. :macro, :function     
  790.      
  791.      :macro is a global (`defmacro') macro.  :function is anything else.
  792.      
  793. :local, :global     
  794.      
  795.      :local is a `labels' or `flet'.  :global is anything else.
  796.      
  797. `(:or {CONTEXT-SPEC}*)'     
  798.      
  799.      True when any supplied CONTEXT-SPEC is true.
  800.      
  801. `(:and {CONTEXT-SPEC}*)'     
  802.      
  803.      True only when all supplied CONTEXT-SPECs are true.
  804.      
  805. `(:not {CONTEXT-SPEC}*)'     
  806.      
  807.      True when CONTEXT-SPEC is false.
  808.      
  809. `(:member {NAME}*)'     
  810.      
  811.      True when the defined name is one of these names (`equal' test.)
  812.      
  813. `(:match {PATTERN}*)'     
  814.      
  815.      True when any of the patterns is a substring of the name.  The name
  816.      is wrapped with `$''s, so "`$FOO'" matches names beginning with
  817.      "`FOO'", etc.
  818.  
  819.  
  820. 
  821. File: cmu-user.info  Node: Context Declaration Example, Prev: Context Declarations, Up: Compilation Units
  822.  
  823. Context Declaration Example
  824. ---------------------------
  825.  
  826.  
  827. Here is a more complex example of `with-compilation-unit' options:
  828.      
  829.      :optimize '(optimize (speed 2) (space 2) (inhibit-warnings 2)
  830.                           (debug 1) (safety 0))
  831.      :optimize-interface '(optimize-interface (safety 1) (debug 1))
  832.      :context-declarations
  833.      '(((:or :external (:and (:match "%") (:match "SET")))
  834.         (declare (optimize-interface (safety 2))))
  835.        ((:or (:and :external :macro)
  836.              (:match "$PARSE-"))
  837.         (declare (optimize (safety 2)))))
  838.  
  839. The `optimize' and `extensions:optimize-interface' declarations (?) set
  840. up the global compilation policy.  The bodies of functions are to be
  841. compiled completely unsafe (`safety 0'), but argument count and weakened
  842. argument type checking is to be done when a function is called (`speed 2
  843. safety 1').
  844.  
  845. The first declaration specifies that all functions that are external or
  846. whose names contain both "`%'" and "`SET'" are to be compiled compiled
  847. with completely safe interfaces (`safety 2').  The reason for this
  848. particular :match rule is that `setf' inverse functions in this system
  849. tend to have both strings in their name somewhere.  We want `setf'
  850. inverses to be safe because they are implicitly called by users even
  851. though their name is not exported.
  852.  
  853. The second declaration makes external macros or functions whose names
  854. start with "`PARSE-'" have safe bodies (as well as interfaces).  This is
  855. desirable because a syntax error in a macro may cause a type error
  856. inside the body.  The :match rule is used because macros often have
  857. auxiliary functions whose names begin with this string.
  858.  
  859. This particular example is used to build part of the standard CMU Common
  860. Lisp system.  Note however, that context declarations must be set up
  861. according to the needs and coding conventions of a particular system;
  862. different parts of CMU Common Lisp are compiled with different context
  863. declarations, and your system will probably need its own declarations.
  864. In particular, any use of the :match option depends on naming
  865. conventions used in coding.
  866.  
  867.  
  868. 
  869. File: cmu-user.info  Node: Interpreting Error Messages, Prev: Compilation Units, Up: The Compiler, Next: Types in Python
  870.  
  871. Interpreting Error Messages
  872. ===========================
  873.  
  874.  
  875. One of Python's unique features is the level of source location information it
  876. provides in error messages.  The error messages contain a lot of detail in a
  877. terse format, to they may be confusing at first.  Error messages will be
  878. illustrated using this example program:
  879.      
  880.      (defmacro zoq (x)
  881.        `(roq (ploq (+ ,x 3))))
  882.      
  883.      (defun foo (y)
  884.        (declare (symbol y))
  885.        (zoq y))
  886.  
  887. The main problem with this program is that it is trying to add `3' to a
  888. symbol.  Note also that the functions `roq' and `ploq' aren't defined
  889. anywhere.
  890.  
  891. * Menu:
  892.  
  893. * The Parts of the Error Message::  
  894. * The Original and Actual Source::  
  895. * The Processing Path::         
  896. * Error Severity::              
  897. * Errors During Macroexpansion::  
  898. * Read Errors::                 
  899. * Error Message Parameterization::  
  900.  
  901.  
  902. 
  903. File: cmu-user.info  Node: The Parts of the Error Message, Prev: Interpreting Error Messages, Up: Interpreting Error Messages, Next: The Original and Actual Source
  904.  
  905. The Parts of the Error Message
  906. ------------------------------
  907.  
  908.  
  909. The compiler will produce this warning:
  910.      
  911.      File: /usr/me/stuff.lisp
  912.      
  913.      In: DEFUN FOO
  914.        (ZOQ Y)
  915.      --> ROQ PLOQ + 
  916.      ==>
  917.        Y Warning: Result is a SYMBOL, not a NUMBER.
  918.  
  919. In this example we see each of the six possible parts of a compiler error
  920. message:
  921.      
  922. `File: /usr/me/stuff.lisp'     
  923.      
  924.      This is the FILE that the compiler read the relevant code from.
  925.      The file name is displayed because it may not be immediately
  926.      obvious when there is an error during compilation of a large
  927.      system, especially when `with-compilation-unit' is used to delay
  928.      undefined warnings.
  929.      
  930. `In: DEFUN FOO'     
  931.      
  932.      This is the DEFINITION or top-level form responsible for the error.
  933.      It is obtained by taking the first two elements of the enclosing
  934.      form whose first element is a symbol beginning with "`DEF'".  If
  935.      there is no enclosing DEFmumble, then the outermost form is used.
  936.      If there are multiple DEFmumbles, then they are all printed from
  937.      the out in, separated by `=>''s.  In this example, the problem was
  938.      in the `defun' for `foo'.
  939.      
  940. `(ZOQ Y)'     
  941.      
  942.      This is the original source form responsible for the error.
  943.      Original source means that the form directly appeared in the
  944.      original input to the compiler, i.e. in the lambda passed to
  945.      `compile' or the top-level form read from the source file.  In this
  946.      example, the expansion of the `zoq' macro was responsible for the
  947.      error.
  948.      
  949. `--> ROQ PLOQ +'      
  950.      
  951.      This is the processing path that the compiler used to produce the
  952.      errorful code.  The processing path is a representation of the
  953.      evaluated forms enclosing the actual source that the compiler
  954.      encountered when processing the original source.  The path is the
  955.      first element of each form, or the form itself if the form is not a
  956.      list.  These forms result from the expansion of macros or
  957.      source-to-source transformation done by the compiler.  In this
  958.      example, the enclosing evaluated forms are the calls to `roq',
  959.      `ploq' and `+'.  These calls resulted from the expansion of the
  960.      `zoq' macro.
  961.      
  962. `==>  Y'     
  963.      
  964.      This is the actual source responsible for the error.  If the actual
  965.      source appears in the explanation, then we print the next enclosing
  966.      evaluated form, instead of printing the actual source twice.  (This
  967.      is the form that would otherwise have been the last form of the
  968.      processing path.)  In this example, the problem is with the
  969.      evaluation of the reference to the variable `y'.
  970.      
  971. `Warning: Result is a SYMBOL, not a NUMBER.'     
  972.      
  973.      This is the EXPLANATION the problem.  In this example, the problem
  974.      is that `y' evaluates to a `symbol', but is in a context where a
  975.      number is required (the argument to `+').
  976.  
  977.  
  978. Note that each part of the error message is distinctively marked:
  979.      
  980.    * `File:' and `In:' mark the file and definition, respectively.
  981.      
  982.    * The original source is an indented form with no prefix.
  983.      
  984.    * Each line of the processing path is prefixed with `-->'.
  985.      
  986.    * The actual source form is indented like the original source, but is
  987.      marked by a preceding `==>' line.  This is like the "macroexpands
  988.      to" notation used in i{Common Lisp: The Language}.
  989.      
  990.    * The explanation is prefixed with the error severity (?), either
  991.      `Error:', `Warning:', or `Note:'.
  992.  
  993.  
  994.  
  995. Each part of the error message is more specific than the preceding one.  If
  996. consecutive error messages are for nearby locations, then the front part of the
  997. error messages would be the same.  In this case, the compiler omits as much of
  998. the second message as in common with the first.  For example:
  999.      
  1000.      File: /usr/me/stuff.lisp
  1001.      
  1002.      In: DEFUN FOO
  1003.        (ZOQ Y)
  1004.      --> ROQ 
  1005.      ==>
  1006.        (PLOQ (+ Y 3))
  1007.      Warning: Undefined function: PLOQ
  1008.      
  1009.      ==>
  1010.        (ROQ (PLOQ (+ Y 3)))
  1011.      Warning: Undefined function: ROQ
  1012.  
  1013. In this example, the file, definition and original source are identical for the
  1014. two messages, so the compiler omits them in the second message.  If consecutive
  1015. messages are entirely identical, then the compiler prints only the first
  1016. message, followed by:
  1017.      
  1018.      [Last message occurs REPEATS times]
  1019.  
  1020. where REPEATS is the number of times the message was given.
  1021.  
  1022. If the source was not from a file, then no file line is printed.  If the
  1023. actual source is the same as the original source, then the processing
  1024. path and actual source will be omitted.  If no forms intervene between
  1025. the original source and the actual source, then the processing path will
  1026. also be omitted.
  1027.  
  1028.  
  1029. 
  1030. File: cmu-user.info  Node: The Original and Actual Source, Prev: The Parts of the Error Message, Up: Interpreting Error Messages, Next: The Processing Path
  1031.  
  1032. The Original and Actual Source
  1033. ------------------------------
  1034.  
  1035.  
  1036. The original source displayed will almost always be a list.  If the actual
  1037. source for an error message is a symbol, the original source will be the
  1038. immediately enclosing evaluated list form.  So even if the offending symbol
  1039. does appear in the original source, the compiler will print the enclosing list
  1040. and then print the symbol as the actual source (as though the symbol were
  1041. introduced by a macro.)
  1042.  
  1043. When the actual source is displayed (and is not a symbol), it will
  1044. always be code that resulted from the expansion of a macro or a
  1045. source-to-source compiler optimization.  This is code that did not
  1046. appear in the original source program; it was introduced by the
  1047. compiler.
  1048.  
  1049. Keep in mind that when the compiler displays a source form in an error message,
  1050. it always displays the most specific (innermost) responsible form.  For
  1051. example, compiling this function:
  1052.      
  1053.      (defun bar (x)
  1054.        (let (a)
  1055.          (declare (fixnum a))
  1056.          (setq a (foo x))
  1057.          a))
  1058.  
  1059. Gives this error message:
  1060.      
  1061.      In: DEFUN BAR
  1062.        (LET (A) (DECLARE (FIXNUM A)) (SETQ A (FOO X)) A)
  1063.      Warning: The binding of A is not a FIXNUM:
  1064.        NIL
  1065.  
  1066. This error message is not saying "there's a problem somewhere in this
  1067. `let'" -- it is saying that there is a problem with the `let' itself.
  1068. In this example, the problem is that `a''s false initial value is not a
  1069. `fixnum'.
  1070.  
  1071.  
  1072. 
  1073. File: cmu-user.info  Node: The Processing Path, Prev: The Original and Actual Source, Up: Interpreting Error Messages, Next: Error Severity
  1074.  
  1075. The Processing Path
  1076. -------------------
  1077.  
  1078.  
  1079. The processing path is mainly useful for debugging macros, so if you don't
  1080. write macros, you can ignore the processing path.  Consider this example:
  1081.      
  1082.      (defun foo (n)
  1083.        (dotimes (i n *undefined*)))
  1084.  
  1085. Compiling results in this error message:
  1086.      
  1087.      In: DEFUN FOO
  1088.        (DOTIMES (I N *UNDEFINED*))
  1089.      --> DO BLOCK LET TAGBODY RETURN-FROM 
  1090.      ==>
  1091.        (PROGN *UNDEFINED*)
  1092.      Warning: Undefined variable: *UNDEFINED*
  1093.  
  1094. Note that `do' appears in the processing path.  This is because `dotimes'
  1095. expands into:
  1096.      
  1097.      (do ((i 0 (1+ i)) (#:g1 n))
  1098.          ((>= i #:g1) *undefined*)
  1099.        (declare (type unsigned-byte i)))
  1100.  
  1101. The rest of the processing path results from the expansion of `do':
  1102.      
  1103.      (block nil
  1104.        (let ((i 0) (#:g1 n))
  1105.          (declare (type unsigned-byte i))
  1106.          (tagbody (go #:g3)
  1107.           #:g2    (psetq i (1+ i))
  1108.           #:g3    (unless (>= i #:g1) (go #:g2))
  1109.                   (return-from nil (progn *undefined*)))))
  1110.  
  1111. In this example, the compiler descended into the `block', `let',
  1112. `tagbody' and `return-from' to reach the `progn' printed as the actual
  1113. source.  This is a place where the "actual source appears in
  1114. explanation" rule was applied.  The innermost actual source form was the
  1115. symbol `*undefined*' itself, but that also appeared in the explanation,
  1116. so the compiler backed out one level.
  1117.  
  1118.  
  1119. 
  1120. File: cmu-user.info  Node: Error Severity, Prev: The Processing Path, Up: Interpreting Error Messages, Next: Errors During Macroexpansion
  1121.  
  1122. Error Severity
  1123. --------------
  1124.  
  1125.  
  1126. There are three levels of compiler error severity:
  1127.      
  1128. Error     
  1129.      
  1130.      This severity is used when the compiler encounters a problem
  1131.      serious enough to prevent normal processing of a form.  Instead of
  1132.      compiling the form, the compiler compiles a call to `error'.
  1133.      Errors are used mainly for signalling syntax errors.  If an error
  1134.      happens during macroexpansion, the compiler will handle it.  The
  1135.      compiler also handles and attempts to proceed from read errors.
  1136.      
  1137. Warning     
  1138.      
  1139.      Warnings are used when the compiler can prove that something bad will happen
  1140.      if a portion of the program is executed, but the compiler can proceed by
  1141.      compiling code that signals an error at runtime if the problem has not been
  1142.      fixed:
  1143.           
  1144.         * Violation of type declarations, or
  1145.           
  1146.         * Function calls that have the wrong number of arguments or malformed keyword
  1147.           argument lists, or
  1148.           
  1149.         * Referencing a variable declared `ignore', or unrecognized
  1150.           declaration specifiers.
  1151.      
  1152.      
  1153.      In the language of the CMU Common Lisp standard, these are
  1154.      situations where the compiler can determine that a situation with
  1155.      undefined consequences or that would cause an error to be signalled
  1156.      would result at runtime.
  1157.      
  1158. Note     
  1159.      
  1160.      Notes are used when there is something that seems a bit odd, but
  1161.      that might reasonably appear in correct programs.
  1162.  
  1163. Note that the compiler does not fully conform to the proposed X3J13
  1164. "compiler-diagnostics" cleanup.  Errors, warnings and notes mostly
  1165. correspond to errors, warnings and style-warnings, but many things that
  1166. the cleanup considers to be style-warnings are printed as warnings
  1167. rather than notes.  Also, warnings, style-warnings and most errors
  1168. aren't really signalled using the condition system.
  1169.  
  1170.  
  1171. 
  1172. File: cmu-user.info  Node: Errors During Macroexpansion, Prev: Error Severity, Up: Interpreting Error Messages, Next: Read Errors
  1173.  
  1174. Errors During Macroexpansion
  1175. ----------------------------
  1176.  
  1177.  
  1178. The compiler handles errors that happen during macroexpansion, turning them
  1179. into compiler errors.  If you want to debug the error (to debug a macro), you
  1180. can set `*break-on-signals*' to `error'.  For example, this definition:
  1181.      
  1182.      (defun foo (e l)
  1183.        (do ((current l (cdr current))
  1184.             ((atom current) nil))
  1185.            (when (eq (car current) e) (return current))))
  1186.  
  1187. gives this error:
  1188.      
  1189.      In: DEFUN FOO
  1190.        (DO ((CURRENT L #) (# NIL)) (WHEN (EQ # E) (RETURN CURRENT)) )
  1191.      Error: (during macroexpansion)
  1192.      
  1193.      Error in function LISP::DO-DO-BODY.
  1194.      DO step variable is not a symbol: (ATOM CURRENT)
  1195.  
  1196.  
  1197.  
  1198.  
  1199. 
  1200. File: cmu-user.info  Node: Read Errors, Prev: Errors During Macroexpansion, Up: Interpreting Error Messages, Next: Error Message Parameterization
  1201.  
  1202. Read Errors
  1203. -----------
  1204.  
  1205.  
  1206. The compiler also handles errors while reading the source.  For example:
  1207.      
  1208.      Error: Read error at 2:
  1209.       "(,/\foo)" Error in function LISP::COMMA-MACRO.  Comma not inside
  1210.      a backquote.
  1211.  
  1212. The "`at 2'" refers to the character position in the source file at
  1213. which the error was signalled, which is generally immediately after the
  1214. erroneous text.  The next line, "`(,/\foo)'", is the line in
  1215. the source that contains the error file position.  The "`/\'"
  1216. indicates the error position within that line (in this example,
  1217. immediately after the offending comma.)
  1218.  
  1219. When in hemlock (or any other EMACS-like editor), you can go to a
  1220. character position with:
  1221.      
  1222.      M-< C-u POSITION C-f
  1223.  
  1224. Note that if the source is from a hemlock buffer, then the position is
  1225. relative to the start of the compiled region or `defun', not the file or
  1226. buffer start.
  1227.  
  1228. After printing a read error message, the compiler attempts to recover
  1229. from the error by backing up to the start of the enclosing top-level
  1230. form and reading again with `*read-suppress*' true.  If the compiler can
  1231. recover from the error, then it substitutes a call to `cerror' for the
  1232. unreadable form and proceeds to compile the rest of the file normally.
  1233.  
  1234. If there is a read error when the file position is at the end of the file
  1235. (i.e., an unexpected EOF error), then the error message looks like this:
  1236.      
  1237.      Error: Read error in form starting at 14:
  1238.       "(defun test ()"
  1239.      Error in function LISP::FLUSH-WHITESPACE.
  1240.      EOF while reading #<Stream for file "/usr/me/test.lisp">
  1241.  
  1242. In this case, "`starting at 14'" indicates the character position at
  1243. which the compiler started reading, i.e. the position before the start
  1244. of the form that was missing the closing delimiter.  The line "`(defun
  1245. test ()'" is first line after the starting position that the compiler
  1246. thinks might contain the unmatched open delimiter.
  1247.  
  1248.  
  1249. 
  1250. File: cmu-user.info  Node: Error Message Parameterization, Prev: Read Errors, Up: Interpreting Error Messages
  1251.  
  1252. Error Message Parameterization
  1253. ------------------------------
  1254.  
  1255.  
  1256. There is some control over the verbosity of error messages.  See also
  1257. undefined-warning-limit *Note Undefined Warnings::,
  1258. `*efficiency-note-limit*' and efficiency-note-cost-threshold ?.
  1259.  
  1260.  
  1261.  
  1262.  -- Variable: *enclosing-source-cutoff*
  1263.      This variable specifies the number of enclosing actual source forms
  1264.      that are printed in full, rather than in the abbreviated processing
  1265.      path format.  Increasing the value from its default of `1' allows
  1266.      you to see more of the guts of the macroexpanded source, which is
  1267.      useful when debugging macros.
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  -- Variable: *error-print-length*
  1273.  
  1274.  -- Variable: *error-print-level*
  1275.      These variables are the print level and print length used in
  1276.      printing error messages.  The default values are `5' and `3'.  If
  1277.      null, the global values of `*print-level*' and `*print-length*' are
  1278.      used.
  1279.  
  1280.  
  1281.  
  1282.  -- Macro: def-source-context name lambda-list {form}*
  1283.  
  1284.      This macro defines how to extract an abbreviated source context
  1285.      from the NAMEd form when it appears in the compiler input.
  1286.      LAMBDA-LIST is a `defmacro' style lambda-list used to parse the
  1287.      arguments.  The BODY should return a list of subforms that can be
  1288.      printed on about one line.  There are predefined methods for
  1289.      `defstruct', `defmethod', etc.  If no method is defined, then the
  1290.      first two subforms are returned.  Note that this facility
  1291.      implicitly determines the string name associated with anonymous
  1292.      functions.
  1293.  
  1294.  
  1295.  
  1296. 
  1297. File: cmu-user.info  Node: Types in Python, Prev: Interpreting Error Messages, Up: The Compiler, Next: Getting Existing Programs to Run
  1298.  
  1299. Types in Python
  1300. ===============
  1301.  
  1302.  
  1303. A big difference between Python and all other Common Lisp compilers
  1304. is the approach to type checking and amount of knowledge about types:
  1305.      
  1306.    * Python treats type declarations much differently that other Lisp
  1307.      compilers do.  Python doesn't blindly believe type declarations; it
  1308.      considers them assertions about the program that should be checked.
  1309.      
  1310.    * Python also has a tremendously greater knowledge of the CMU Common
  1311.      Lisp type system than other compilers.  Support is incomplete only
  1312.      for the `not', `and' and `satisfies' types.
  1313.  
  1314. See also sections ? and ?.
  1315.  
  1316.  
  1317. * Menu:
  1318.  
  1319. * Compile Time Type Errors::    
  1320. * Precise Type Checking::       
  1321. * Weakened Type Checking::      
  1322.  
  1323.  
  1324. 
  1325. File: cmu-user.info  Node: Compile Time Type Errors, Prev: Types in Python, Up: Types in Python, Next: Precise Type Checking
  1326.  
  1327. Compile Time Type Errors
  1328. ------------------------
  1329.  
  1330.  
  1331. If the compiler can prove at compile time that some portion of the program
  1332. cannot be executed without a type error, then it will give a warning at compile
  1333. time.  It is possible that the offending code would never actually be executed
  1334. at run-time due to some higher level consistency constraint unknown to the
  1335. compiler, so a type warning doesn't always indicate an incorrect program.  For
  1336. example, consider this code fragment:
  1337.      
  1338.      (defun raz (foo)
  1339.        (let ((x (case foo
  1340.                   (:this 13)
  1341.                   (:that 9)
  1342.                   (:the-other 42))))
  1343.          (declare (fixnum x))
  1344.          (foo x)))
  1345.  
  1346. Compilation produces this warning:
  1347.      
  1348.      In: DEFUN RAZ
  1349.        (CASE FOO (:THIS 13) (:THAT 9) (:THE-OTHER 42))
  1350.      --> LET COND IF COND IF COND IF 
  1351.      ==>
  1352.        (COND)
  1353.      Warning: This is not a FIXNUM:
  1354.        NIL
  1355.  
  1356. In this case, the warning is telling you that if `foo' isn't any of
  1357. `:this', `:that' or `:the-other', then `x' will be initialized to false,
  1358. which the `fixnum' declaration makes illegal.  The warning will go away
  1359. if `ecase' is used instead of `case', or if `:the-other' is changed to
  1360. true.
  1361.  
  1362. This sort of spurious type warning happens moderately often in the
  1363. expansion of complex macros and in inline functions.  In such cases,
  1364. there may be dead code that is impossible to correctly execute.  The
  1365. compiler can't always prove this code is dead (could never be executed),
  1366. so it compiles the erroneous code (which will always signal an error if
  1367. it is executed) and gives a warning.
  1368.  
  1369.  
  1370.  -- Function: required-argument
  1371.      This function can be used as the default value for keyword
  1372.      arguments that must always be supplied.  Since it is known by the
  1373.      compiler to never return, it will avoid any compile-time type
  1374.      warnings that would result from a default value inconsistent with
  1375.      the declared type.  When this function is called, it signals an
  1376.      error indicating that a required keyword argument was not supplied.
  1377.      This function is also useful for `defstruct' slot defaults
  1378.      corresponding to required arguments.  ?.
  1379.      
  1380.      Although this function is a CMU extension, it is relatively harmless to use it
  1381.      in otherwise portable code, since you can easily define it yourself:
  1382.           
  1383.           (defun required-argument ()
  1384.             (error "A required keyword argument was not supplied."))
  1385.      
  1386.  
  1387.  
  1388. Type warnings are inhibited when the `extensions:inhibit-warnings'
  1389. optimization quality is `3' (?.)  This can be used in a local
  1390. declaration to inhibit type warnings in a code fragment that has
  1391. spurious warnings.
  1392.  
  1393.  
  1394. 
  1395. File: cmu-user.info  Node: Precise Type Checking, Prev: Compile Time Type Errors, Up: Types in Python, Next: Weakened Type Checking
  1396.  
  1397. Precise Type Checking
  1398. ---------------------
  1399.  
  1400.  
  1401. With the default compilation policy, all type assertions (3) (*Note
  1402. Precise Type Checking-Footnotes::) are precisely checked.  Precise
  1403. checking means that the check is done as though `typep' had been called
  1404. with the exact type specifier that appeared in the declaration.  Python
  1405. uses POLICY to determine whether to trust type assertions (?).  Type
  1406. assertions from declarations are indistinguishable from the type
  1407. assertions on arguments to built-in functions.  In Python, adding type
  1408. declarations makes code safer.
  1409.  
  1410. If a variable is declared to be `(integer 3 17)', then its value must
  1411. always always be an integer between `3' and `17'.  If multiple type
  1412. declarations apply to a single variable, then all the declarations must
  1413. be correct; it is as though all the types were intersected producing a
  1414. single `and' type specifier.
  1415.  
  1416. Argument type declarations are automatically enforced.  If you declare
  1417. the type of a function argument, a type check will be done when that
  1418. function is called.  In a function call, the called function does the
  1419. argument type checking, which means that a more restrictive type
  1420. assertion in the calling function (e.g., from `the') may be lost.
  1421.  
  1422. The types of structure slots are also checked.  The value of a structure
  1423. slot must always be of the type indicated in any `:type' slot option.
  1424. (4) (*Note Precise Type Checking-Footnotes::) Because of precise type
  1425. checking, the arguments to slot accessors are checked to be the correct
  1426. type of structure.
  1427.  
  1428. In traditional Common Lisp compilers, not all type assertions are
  1429. checked, and type checks are not precise.  Traditional compilers blindly
  1430. trust explicit type declarations, but may check the argument type
  1431. assertions for built-in functions.  Type checking is not precise, since
  1432. the argument type checks will be for the most general type legal for
  1433. that argument.  In many systems, type declarations suppress what little
  1434. type checking is being done, so adding type declarations makes code
  1435. unsafe.  This is a problem since it discourages writing type
  1436. declarations during initial coding.  In addition to being more error
  1437. prone, adding type declarations during tuning also loses all the
  1438. benefits of debugging with checked type assertions.
  1439.  
  1440. To gain maximum benefit from Python's type checking, you should always
  1441. declare the types of function arguments and structure slots as precisely
  1442. as possible.  This often involves the use of `or', `member' and other
  1443. list-style type specifiers.  Paradoxically, even though adding type
  1444. declarations introduces type checks, it usually reduces the overall
  1445. amount of type checking.  This is especially true for structure slot
  1446. type declarations.
  1447.  
  1448. Python uses the `safety' optimization quality (rather than presence or
  1449. absence of declarations) to choose one of three levels of run-time type
  1450. error checking: ?.  ? for more information about types in Python.
  1451.  
  1452.  
  1453. 
  1454.